package com.gs.sqlite.controller;

import com.gs.sqlite.mapper.HelloMapper;
import com.gs.sqlite.model.HelloModel;
import com.gs.sqlite.service.HelloService;
import org.apache.ibatis.cursor.Cursor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.util.Iterator;
import java.util.List;

@RestController
public class HelloController {
    @Autowired
    HelloMapper helloMapper;

    @Autowired
    HelloService helloService;

    @GetMapping("/all")
    public String selectAll(){
        Cursor<HelloModel> cursor = helloMapper.selectNext();//通过游标逐条访问数据
        Iterator<HelloModel> iterator = cursor.iterator();
        while (iterator.hasNext()) {
            HelloModel helloModel = iterator.next();
            System.out.println(helloModel.getText());
        }
        return "ok";
    }
    @GetMapping("/list")
    public List<HelloModel> getList(){
        return helloService.selectAll();
    }
}
